let Toast = {

}

Toast.install = function (Vue, options) {

  let opt = {

    // 默认显示位置
    defaultType: 'center',

    // 持续时间
    duration: 1500

  }
  for (let property in options) {
    opt[property] = options[property]
  }

  Vue.prototype.$toast = (tips, type) => {
    if (type) {
      opt.defaultType = type
    }

    let toastTpl = Vue.extend({
      template: `<div class="vue-toast toast-${opt.defaultType}">${tips}</div>`
    })

    let tpl = new toastTpl().$mount().$el

    document.body.appendChild(tpl)

    setTimeout(function () {
      document.body.removeChild(tpl)
    }, opt.duration)

  }

  ['bottom', 'center', 'top'].forEach(type => {
    Vue.prototype.$toast[type] = (tips) => {
      return Vue.prototype.$toast(tips, type)
    }
  })

}

export {
  Toast
}